package com.credit.shtl.dao.classroom;/**
 * @Classname ClassDAO
 * @Description TODO
 * @Date 2020/10/22 20:58
 * @Created by SHTL
 */

import com.credit.shtl.dao.classroom.Classroom;
import com.credit.shtl.dao.student.StudentUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

/**
 * @InterfaceName ClassDAO
 * @Description 教室信息DAO接口
 * @Author SHTL
 * @Date 2020/10/22 20:58
 * @Version 1.0
 */
public interface ClassDAO extends JpaRepository<Classroom,String>,
        JpaSpecificationExecutor<Classroom> {

    // 根据 教学楼信息 tung 获取上课教室信息
    @Modifying
    @Query(value = "select classroom from classroom GROUP BY id",nativeQuery = true)
    List<Object> getByClassroom();


    // 获取所有教室信息， like
    @Modifying
    @Query(value = "select * from classroom as c where classroom like concat('%',:like,'%') ORDER BY classroom",nativeQuery = true)
    List<Classroom> findAllRooms(@Param("like") String like);

    // like
    List<Classroom> findByClassroomLike(String like);


    // 更具 classroom （教室名称） 检查，看是否有重复数据，没有再进行添加操作
    @Modifying
    @Query(value = "select * from classroom as c where c.classroom = :classname",nativeQuery = true)
    List<Classroom> classroomcheck(@Param("classname") String classname);


    // 根据 classroom （教室名称）进行删除数据
    @Transactional
    @Modifying
    @Query(value = "delete from classroom as c where c.classroom = :classname",nativeQuery = true)
    Integer deleteClassroomByName(@Param("classname") String classname);
}
